package com.bilubi.reggie.reggie.service.Impl;

import com.bilubi.reggie.reggie.bean.User;
import com.bilubi.reggie.reggie.mapper.UserMapper;
import com.bilubi.reggie.reggie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User getUserByPhone(String phone) {
        User user = userMapper.selectUserByPhone(phone);
        if (user == null) {
            User newUser = new User();
            newUser.setPhone(phone);
            userMapper.insertSelective(newUser);
            return userMapper.selectUserByPhone(phone);
        }
        return user;
    }
}
